-- Freeslots + State/Object Definitions
freeslot("S_FFZBUSH", "MT_FFZBUSH", "SPR_FFZ1", "S_FFZFLOWER", "MT_FFZFLOWER", "SPR_FFZ2", "S_FFZTREE", "MT_FFZTREE", "SPR_FFZ3")
-- FFZ Bush + Bushpole
states[S_FFZBUSH] = {SPR_FFZ1, A, -1, nil, 0, 0, S_FFZBUSH}
mobjinfo[MT_FFZBUSH] = {
	//$Sprite FFZ1A0
	//$Name FFZ Bush + Bushpole
	doomednum = 2900,
	spawnstate = S_FFZBUSH,
	flags = MF_NOBLOCKMAP|MF_NOCLIP|MF_SCENERY,
}
-- FFZ Flower
states[S_FFZFLOWER] = {SPR_FFZ2, A, -1, nil, 0, 0, S_FFZFLOWER}
mobjinfo[MT_FFZFLOWER] = {
	//$Sprite FFZ2A0
	//$Name FFZ Flower
	doomednum = 2901,
	spawnstate = S_FFZFLOWER,
	flags = MF_NOBLOCKMAP|MF_NOCLIP|MF_SCENERY,
}
-- FFZ Tree
states[S_FFZTREE] = {SPR_FFZ3, A, -1, nil, 0, 0, S_FFZTREE}
mobjinfo[MT_FFZTREE] = {
	//$Sprite FFZ3A0
	//$Name FFZ Tree
	doomednum = 2902,
	spawnstate = S_FFZTREE,
	flags = MF_NOBLOCKMAP|MF_NOCLIP|MF_SCENERY,
}

-- load spikeball sprite
freeslot("SPR_FFZS")
-- handle spikeball shit, srb2 is literally gay so we need a thinkframe :V
local mace_array = {}
addHook("ThinkFrame", do
    if not mapheaderinfo[gamemap].ffmace or not #mace_array return end
    for i = 1, #mace_array do
        if (mace_array[i] and mace_array[i].valid)
            mace_array[i].sprite = SPR_FFZS
            mace_array[i].frame = A
        end
    end
end)
-- MapLoad hook to load custom options
addHook("MapLoad", do
	mace_array = {}
    for m in thinkers.iterate("mobj")
        if (m and m.valid)
            if (m.type == MT_FFZBUSH) -- bush settings
				-- change frame based on flags
                if (m.flags2 & MF2_AMBUSH) -- change frame if ambush is flagged
                    -- if objectspecial is also flagged, change frame to 2 (bushpole), else change frame to 1 (big bush)
                    m.frame = (m.spawnpoint.options & MTF_OBJECTSPECIAL) and 2 or 1
                end
				m.flags = $|MF_NOTHINK -- give them MF_NOTHINK to kill off any extra processing
            elseif (m.type == MT_FFZFLOWER) -- flower settings
                -- change frame based on flags
                if (m.flags2 & MF2_AMBUSH) -- change frame if ambush is flagged
                    -- if objectspecial is also flagged, change frame to 2 (tall flower), else change frame to 1 (medium flower)
                    m.frame = (m.spawnpoint.options & MTF_OBJECTSPECIAL) and 2 or 1
                end
				m.flags = $|MF_NOTHINK -- give them MF_NOTHINK to kill off any extra processing
			elseif (m.type == MT_FFZTREE) -- tree settings
				m.scale = (m.flags2 & MF2_AMBUSH) and (mapobjectscale)*7/4 or (mapobjectscale)
				m.flags = $|MF_NOTHINK -- give them MF_NOTHINK to kill off any extra processing
			elseif m.type == MT_BIGMACE or m.type == MT_SMALLMACE
				mace_array[#mace_array+1] = m
			end
        end
    end
end)
